#coding=utf-8
import re

'''
' [多行]2.6.7-1 使用block要注意循环引用问题
'''
def mzcc_udrule_mul2_6_7__1(bufferItem, lineContext):

    bufferItem.lineNum = lineContext.curLineNum;

    # 逻辑开始
    if None == bufferItem.userDefineInfo:
        bufferItem.userDefineInfo = 0;

        results = re.findall(r"{", lineContext.curNspLine);
        bufferItem.userDefineInfo += len(results);
        results = re.findall(r"}", lineContext.curNspLine);
        bufferItem.userDefineInfo -= len(results);

        if 0 == bufferItem.userDefineInfo:
            bufferItem.userDefineInfo = None;
            return 0;

        # 启动行不检测
        return 2;

    results = re.findall(r"{", lineContext.curNspLine);
    bufferItem.userDefineInfo += len(results);
    results = re.findall(r"}", lineContext.curNspLine);
    bufferItem.userDefineInfo -= len(results);

    if 0 == bufferItem.userDefineInfo:
        bufferItem.userDefineInfo = None;
        return 0;

    # 检测到局部变量调用（如：_contentView）
    results = re.findall(r"\W_[a-z]", lineContext.curLine);
    if 0 != len(results):
        subResults = re.findall(r"(\[|:)_[a-z]", lineContext.curNspLine);
        if 0 != len(subResults):
            bufferItem.userDefineInfo = None;
            return 1;
        subResults = re.findall(r"_.*:|_.*]", lineContext.curNspLine);
        if 0 == len(subResults):
            bufferItem.userDefineInfo = None;
            return 1;

    # 屏蔽self检测的关键字
    passKeys = ["@strongify\(", "SafeStrongSelf"];

    for tmpKey in passKeys:
        results = re.findall(tmpKey, lineContext.curNspLine);
        if 0 != len(results):
            return 2;

    results = re.findall(r"\Wself\W", lineContext.curLine);
    if 0 != len(results):
        bufferItem.userDefineInfo = None;
        return 1;

    return 2;
